﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class Admin_ProductDisable : System.Web.UI.Page
{
    ShopLaptopConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new ShopLaptopConnection();
        if (!IsPostBack)
        {
            List<Category> list = conn.GetAllCategoryByStatus1();
            foreach (Category  cate in list)
            {
                ListItem item = new ListItem(cate.CateName,cate.CateID.ToString());
                drdlCategory.Items.Add(item);
            }
            //drdlCategory.DataSource = list;
            //drdlCategory.DataTextField = "CateName";
            //drdlCategory.DataValueField = "CateID";
            //drdlCategory.DataBind();
        }
    }
    protected void drdlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        grProductDisable.DataSource = "";
        grProductDisable.DataBind();
        try
        {
            List<Product> list = conn.GetProduct0ByCateID(Convert.ToInt32(drdlCategory.SelectedValue));
            grProductDisable.DataKeyNames = new string[] { "ProID" };
            grProductDisable.DataSource = list;
            grProductDisable.DataBind();
        }
        catch 
        {
            
        }
    }
    protected void grProductDisable_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int check = 0;
        int id = Convert.ToInt32(grProductDisable.Rows[e.RowIndex].Cells[0].Text);
        check = conn.SetProductStatus1(id);
        if (check > 0)
        {
            DisplayByCategory();
        }
    }

    protected void DisplayByCategory()
    {
        grProductDisable.DataSource = "";
        grProductDisable.DataBind();
        List<Product> list = conn.GetProduct0ByCateID(Convert.ToInt32(drdlCategory.SelectedValue));
        grProductDisable.DataKeyNames = new string[] { "ProID" };
        grProductDisable.DataSource = list;
        grProductDisable.DataBind();
    } 
}
